diff options
Diffstat (limited to 'web/attachments/66459-nagios-plugins-1.3.1-check-dns.patch')
-rw-r--r-- | web/attachments/66459-nagios-plugins-1.3.1-check-dns.patch | 646 |
1 files changed, 646 insertions, 0 deletions
diff --git a/web/attachments/66459-nagios-plugins-1.3.1-check-dns.patch b/web/attachments/66459-nagios-plugins-1.3.1-check-dns.patch new file mode 100644 index 0000000..0f3d631 --- /dev/null +++ b/web/attachments/66459-nagios-plugins-1.3.1-check-dns.patch | |||
@@ -0,0 +1,646 @@ | |||
1 | diff -ruN nagios-plugins-1.3.1/plugins/check_dns.c nagios-plugins-1.3.1-new/plugins/check_dns.c | ||
2 | --- nagios-plugins-1.3.1/plugins/check_dns.c 2003-05-31 15:39:33.000000000 +0100 | ||
3 | +++ nagios-plugins-1.3.1-new/plugins/check_dns.c 2003-07-14 19:59:16.000000000 +0100 | ||
4 | @@ -11,6 +11,7 @@ | ||
5 | * Notes: | ||
6 | * - Safe popen added by Karl DeBisschop 9-11-99 | ||
7 | * - expected-address parameter added by Alex Chaffee - 7 Oct 2002 | ||
8 | + * - extended to use RESOLVER, HOST or NSLOOKUP by Howard Wilkinson - 24 March 2003 | ||
9 | * | ||
10 | * Command line: (see print_usage) | ||
11 | * | ||
12 | @@ -46,6 +47,28 @@ | ||
13 | |||
14 | #include "common.h" | ||
15 | #include "popen.h" | ||
16 | + | ||
17 | +#ifdef USE_NSLOOKUP | ||
18 | +# if !defined(NSLOOKUP_COMMAND) | ||
19 | +# error "Need NSLOOKUP to use this option" | ||
20 | +# endif | ||
21 | +#endif | ||
22 | +#ifdef USE_HOST | ||
23 | +# if !defined(HOST_COMMAND) | ||
24 | +# error "Need HOST to use this option" | ||
25 | +# endif | ||
26 | +#endif | ||
27 | +#if defined(USE_NSLOOKUP) | ||
28 | +# undef USE_HOST | ||
29 | +# undef USE_RESOLVER | ||
30 | +#elif defined(USE_HOST) | ||
31 | +# undef USE_RESOLVER | ||
32 | +#elif !defined(USE_RESOLVER) | ||
33 | +# define USE_NSLOOKUP | ||
34 | +#endif | ||
35 | +#ifdef USE_RESOLVER | ||
36 | +#include "netutils.h" | ||
37 | +#endif | ||
38 | #include "utils.h" | ||
39 | |||
40 | const char *progname = "check_dns"; | ||
41 | @@ -58,7 +81,9 @@ | ||
42 | void print_help (void); | ||
43 | int error_scan (char *); | ||
44 | |||
45 | -#define ADDRESS_LENGTH 256 | ||
46 | +#define ADDRESS_LENGTH 10240 | ||
47 | +#define RRTYPE_LENGTH 32 | ||
48 | +char record_type[RRTYPE_LENGTH] = "A"; | ||
49 | char query_address[ADDRESS_LENGTH] = ""; | ||
50 | char dns_server[ADDRESS_LENGTH] = ""; | ||
51 | char ptr_server[ADDRESS_LENGTH] = ""; | ||
52 | @@ -69,144 +94,293 @@ | ||
53 | int | ||
54 | main (int argc, char **argv) | ||
55 | { | ||
56 | - char *command_line = NULL; | ||
57 | - char input_buffer[MAX_INPUT_BUFFER]; | ||
58 | - char *output = NULL; | ||
59 | - char *address = NULL; | ||
60 | - char *temp_buffer = NULL; | ||
61 | - int result = STATE_UNKNOWN; | ||
62 | - | ||
63 | - /* Set signal handling and alarm */ | ||
64 | - if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { | ||
65 | - printf ("Cannot catch SIGALRM"); | ||
66 | - return STATE_UNKNOWN; | ||
67 | + char *command_line = NULL; | ||
68 | + char input_buffer[MAX_INPUT_BUFFER]; | ||
69 | + char *output = NULL; | ||
70 | + char *address = NULL; | ||
71 | + char *temp_buffer = NULL; | ||
72 | + int result = STATE_UNKNOWN; | ||
73 | + int linecnt = 0; | ||
74 | + | ||
75 | + /* Set signal handling and alarm */ | ||
76 | + if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { | ||
77 | + printf ("Cannot catch SIGALRM"); | ||
78 | + return STATE_UNKNOWN; | ||
79 | + } | ||
80 | + if (process_arguments (argc, argv) != OK) { | ||
81 | + print_usage (); | ||
82 | + return STATE_UNKNOWN; | ||
83 | + } | ||
84 | + /* get the command to run */ | ||
85 | +#ifdef USE_RESOLVER | ||
86 | +#error "THIS CODE DOES NOT WORK" | ||
87 | + { | ||
88 | + int i; | ||
89 | + struct hostent *response; | ||
90 | + res_init(); | ||
91 | + if (strlen(dns_server)) { | ||
92 | + if ((response=gethostbyname(dns_server)) == NULL) { | ||
93 | + printf ("DNS problem = server %s can not be resolved %s\n", | ||
94 | + dns_server, strerror(h_errno)); | ||
95 | + return STATE_CRITICAL; | ||
96 | + } else { | ||
97 | + _res.nscount = response->h_length; | ||
98 | + for (i = 0; i < response->h_length && i < MAXNS; i++) { | ||
99 | + if (response->h_addr_list[i] == NULL) { | ||
100 | + break; | ||
101 | + } | ||
102 | + _res.nsaddr_list[i].sin_family = AF_INET; | ||
103 | + _res.nsaddr_list[i].sin_port = NS_DEFAULTPORT; | ||
104 | + _res.nsaddr_list[i].sin_addr.s_addr = ((struct in_addr *)response->h_addr_list[i])->s_addr; | ||
105 | } | ||
106 | - | ||
107 | - if (process_arguments (argc, argv) != OK) { | ||
108 | - print_usage (); | ||
109 | - return STATE_UNKNOWN; | ||
110 | + } | ||
111 | + _res.options &= ~(RES_RECURSE|RES_DEFNAMES); | ||
112 | + } | ||
113 | + if ((response=gethostbyname(query_address)) == NULL) { | ||
114 | + asprintf (&output, "lookup failed with %s", strerror(h_errno)); | ||
115 | + result = STATE_CRITICAL; | ||
116 | + } else { | ||
117 | + int len=0; | ||
118 | + struct in_addr in; | ||
119 | + for (i = 0; i < response->h_length; i++) { | ||
120 | + if (response->h_addr_list[i] == NULL) { | ||
121 | + break; | ||
122 | } | ||
123 | - | ||
124 | - /* get the command to run */ | ||
125 | - asprintf (&command_line, "%s %s %s", NSLOOKUP_COMMAND, query_address, dns_server); | ||
126 | - | ||
127 | - alarm (timeout_interval); | ||
128 | - time (&start_time); | ||
129 | - | ||
130 | - if (verbose) | ||
131 | - printf ("%s\n", command_line); | ||
132 | - /* run the command */ | ||
133 | - child_process = spopen (command_line); | ||
134 | - if (child_process == NULL) { | ||
135 | - printf ("Could not open pipe: %s\n", command_line); | ||
136 | - return STATE_UNKNOWN; | ||
137 | + memcpy(&in, ((struct in_addr *)response->h_addr_list[i]), sizeof(in)); | ||
138 | + len+=strlen(inet_ntoa(in))+1; | ||
139 | + } | ||
140 | + address =(char *)malloc(len); | ||
141 | + address[0]='\0'; | ||
142 | + for (i = 0; i < response->h_length; i++) { | ||
143 | + if (response->h_addr_list[i] == NULL) { | ||
144 | + break; | ||
145 | } | ||
146 | - | ||
147 | - child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); | ||
148 | - if (child_stderr == NULL) | ||
149 | - printf ("Could not open stderr for %s\n", command_line); | ||
150 | - | ||
151 | - /* scan stdout */ | ||
152 | - while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { | ||
153 | - | ||
154 | - if (verbose) | ||
155 | - printf ("%s\n", input_buffer); | ||
156 | - | ||
157 | - if (strstr (input_buffer, ".in-addr.arpa")) { | ||
158 | - if ((temp_buffer = strstr (input_buffer, "name = "))) | ||
159 | - address = strscpy (address, temp_buffer + 7); | ||
160 | - else { | ||
161 | - output = strscpy (output, "Unknown error (plugin)"); | ||
162 | - result = STATE_WARNING; | ||
163 | - } | ||
164 | - } | ||
165 | - | ||
166 | - /* the server is responding, we just got the host name... */ | ||
167 | - if (strstr (input_buffer, "Name:")) { | ||
168 | - | ||
169 | - /* get the host address */ | ||
170 | - if (!fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) | ||
171 | - break; | ||
172 | - | ||
173 | - if (verbose) | ||
174 | - printf ("%s\n", input_buffer); | ||
175 | - | ||
176 | - if ((temp_buffer = index (input_buffer, ':'))) { | ||
177 | - temp_buffer++; | ||
178 | - /* Strip leading spaces */ | ||
179 | - for (; *temp_buffer != '\0' && *temp_buffer == ' '; temp_buffer++) | ||
180 | - /* NOOP */; | ||
181 | - address = strdup (temp_buffer); | ||
182 | - strip (address); | ||
183 | - if (address==NULL || strlen(address)==0) | ||
184 | - terminate (STATE_CRITICAL, | ||
185 | - "DNS CRITICAL - '%s' returned empty host name string\n", | ||
186 | - NSLOOKUP_COMMAND); | ||
187 | - result = STATE_OK; | ||
188 | - } | ||
189 | - else { | ||
190 | - output = strdup ("Unknown error (plugin)"); | ||
191 | - result = STATE_WARNING; | ||
192 | - } | ||
193 | - | ||
194 | - break; | ||
195 | - } | ||
196 | - | ||
197 | - result = error_scan (input_buffer); | ||
198 | - if (result != STATE_OK) { | ||
199 | - output = strscpy (output, 1 + index (input_buffer, ':')); | ||
200 | - break; | ||
201 | - } | ||
202 | - | ||
203 | + memcpy(&in, ((struct in_addr*)response->h_addr_list[i]), sizeof(in)); | ||
204 | + strcat(address, inet_ntoa(in)); | ||
205 | + strcat(address, ","); | ||
206 | + } | ||
207 | + address[strlen(address)-1]='\0'; | ||
208 | + result = STATE_OK; | ||
209 | + } | ||
210 | + } | ||
211 | +#endif | ||
212 | +#ifdef USE_NSLOOKUP | ||
213 | + asprintf (&command_line, "%s -timeout=%d -query=%s %s %s", | ||
214 | + NSLOOKUP_COMMAND, timeout_interval-1, | ||
215 | + record_type, query_address, dns_server); | ||
216 | +#endif | ||
217 | +#ifdef USE_HOST | ||
218 | +#error "HOST IS NOT IMPLEMENTED YET" | ||
219 | + asprintf (&command_line, "%s -W %d -t %s %s %s", | ||
220 | + HOST_COMMAND, timeout_interval-1, | ||
221 | + record_type, query_address, dns_server); | ||
222 | +#endif | ||
223 | + alarm (timeout_interval); | ||
224 | + time (&start_time); | ||
225 | + if (verbose) | ||
226 | + printf ("%s\n", command_line); | ||
227 | + /* run the command */ | ||
228 | + child_process = spopen (command_line); | ||
229 | + if (child_process == NULL) { | ||
230 | + printf ("Could not open pipe: %s\n", command_line); | ||
231 | + return STATE_UNKNOWN; | ||
232 | + } | ||
233 | + child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); | ||
234 | + if (child_stderr == NULL) | ||
235 | + printf ("Could not open stderr for %s\n", command_line); | ||
236 | +#ifdef USE_NSLOOKUP | ||
237 | + /* scan stdout */ | ||
238 | + while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { | ||
239 | + if (verbose) | ||
240 | + printf ("%s\n", input_buffer); | ||
241 | + if (linecnt == 0) { | ||
242 | + /* First line should be server name */ | ||
243 | + if (strstr (input_buffer, "Server:") != input_buffer) { | ||
244 | + output = strscpy (output, "NSLOOKUP error (plugin) - no Server line found"); | ||
245 | + result = STATE_WARNING; | ||
246 | + } | ||
247 | + linecnt++; | ||
248 | + } else if (linecnt == 1) { | ||
249 | + /* Next line is server address */ | ||
250 | + if (strstr (input_buffer, "Address:") != input_buffer) { | ||
251 | + output = (output == NULL) | ||
252 | + ?strscpy (output, "NSLOOKUP error (plugin) - no Address line found") | ||
253 | + :strscat (output, ", no Address line found"); | ||
254 | + result = STATE_WARNING; | ||
255 | + } | ||
256 | + linecnt++; | ||
257 | + } else { | ||
258 | + linecnt++; | ||
259 | + strip(input_buffer); | ||
260 | + if (strstr (input_buffer, ".in-addr.arpa")) { | ||
261 | + if ((temp_buffer = strstr (input_buffer, "name = "))) | ||
262 | + address = strscpy (address, temp_buffer + 7); | ||
263 | + else { | ||
264 | + output = strscpy (output, "Unknown error (plugin)"); | ||
265 | + result = STATE_WARNING; | ||
266 | } | ||
267 | - | ||
268 | - /* scan stderr */ | ||
269 | - while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { | ||
270 | - if (error_scan (input_buffer) != STATE_OK) { | ||
271 | - result = max_state (result, error_scan (input_buffer)); | ||
272 | - output = strscpy (output, 1 + index (input_buffer, ':')); | ||
273 | - } | ||
274 | + continue; | ||
275 | + } else if ((temp_buffer = strstr (input_buffer, "canonical name ="))) { | ||
276 | + address = strscat (address, temp_buffer + strlen("cannonical name =")); | ||
277 | + continue; | ||
278 | + } else if ((temp_buffer = strstr (input_buffer, "hinfo ="))) { | ||
279 | + address = strscat (address, temp_buffer + strlen("hinfo =")); | ||
280 | + continue; | ||
281 | + } else if ((temp_buffer = strstr (input_buffer, "mail exchanger ="))) { | ||
282 | + address = strscat (address, temp_buffer + strlen("mail exchanger =")); | ||
283 | + continue; | ||
284 | + } else if ((temp_buffer = strstr (input_buffer, "nameserver ="))) { | ||
285 | + address = strscat (address, temp_buffer + strlen("nameserver =")); | ||
286 | + continue; | ||
287 | + } else if ((temp_buffer = strstr (input_buffer, "text ="))) { | ||
288 | + address = strscat (address, temp_buffer + strlen("text =")); | ||
289 | + continue; | ||
290 | + } else if (strcasecmp(record_type, "SOA") == 0) { | ||
291 | + if (strncasecmp(input_buffer, query_address, strlen(query_address)) == 0) { | ||
292 | + /* Read in SOA */ | ||
293 | + while(fgets(input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { | ||
294 | + if (verbose) | ||
295 | + printf ("%s\n", input_buffer); | ||
296 | + strip(input_buffer); | ||
297 | + address = strscat(address, input_buffer+1); | ||
298 | + if (strstr(input_buffer, "minimum =")) | ||
299 | + break; | ||
300 | + } | ||
301 | + continue; | ||
302 | } | ||
303 | - | ||
304 | - /* close stderr */ | ||
305 | - (void) fclose (child_stderr); | ||
306 | - | ||
307 | - /* close stdout */ | ||
308 | - if (spclose (child_process)) { | ||
309 | - result = max_state (result, STATE_WARNING); | ||
310 | - if (!strcmp (output, "")) | ||
311 | - output = strscpy (output, "nslookup returned error status"); | ||
312 | + } else if (strstr (input_buffer, "Name:")) { | ||
313 | + /* the server is responding, we just got the host name... */ | ||
314 | + /* get the host address */ | ||
315 | + if (!fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) | ||
316 | + break; | ||
317 | + strip (input_buffer); | ||
318 | + if (verbose) | ||
319 | + printf ("%s\n", input_buffer); | ||
320 | + if ((temp_buffer = index (input_buffer, ':'))) { | ||
321 | + address = strscpy (address, temp_buffer + 2); | ||
322 | + strip (address); | ||
323 | + result = STATE_OK; | ||
324 | + } else { | ||
325 | + output = strscpy (output, "Unknown error (plugin)"); | ||
326 | + result = STATE_WARNING; | ||
327 | } | ||
328 | - | ||
329 | - /* If we got here, we should have an address string, | ||
330 | - and we can segfault if we do not */ | ||
331 | + continue; | ||
332 | + } | ||
333 | + } | ||
334 | + result = error_scan (input_buffer); | ||
335 | + if (result != STATE_OK) { | ||
336 | + output = strscpy (output, 1 + index (input_buffer, ':')); | ||
337 | + break; | ||
338 | + } | ||
339 | + } | ||
340 | + /* scan stderr */ | ||
341 | + while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { | ||
342 | + if (error_scan (input_buffer) != STATE_OK) { | ||
343 | + result = max_state (result, error_scan (input_buffer)); | ||
344 | + output = strscpy (output, 1 + index (input_buffer, ':')); | ||
345 | + } | ||
346 | + } | ||
347 | + /* close stderr */ | ||
348 | + (void) fclose (child_stderr); | ||
349 | + /* close stdout */ | ||
350 | + if (spclose (child_process)) { | ||
351 | + result = max_state (result, STATE_WARNING); | ||
352 | + if (!strcmp (output, "")) | ||
353 | + output = strscpy (output, "nslookup returned error status"); | ||
354 | + } | ||
355 | +#endif | ||
356 | +#ifdef USE_HOST | ||
357 | +#error "HOST IS NOT IMPLEMENTED YET" | ||
358 | + /* scan stdout */ | ||
359 | + while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { | ||
360 | + if (verbose) | ||
361 | + printf ("%s\n", input_buffer); | ||
362 | + if (strstr (input_buffer, ".in-addr.arpa")) { | ||
363 | + if ((temp_buffer = strstr (input_buffer, "name = "))) | ||
364 | + address = strscpy (address, temp_buffer + 7); | ||
365 | + else { | ||
366 | + output = strscpy (output, "Unknown error (plugin)"); | ||
367 | + result = STATE_WARNING; | ||
368 | + } | ||
369 | + } | ||
370 | + /* the server is responding, we just got the host name... */ | ||
371 | + if (strstr (input_buffer, "Name:")) { | ||
372 | + /* get the host address */ | ||
373 | + if (!fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) | ||
374 | + break; | ||
375 | + if (verbose) | ||
376 | + printf ("%s\n", input_buffer); | ||
377 | + if ((temp_buffer = index (input_buffer, ':'))) { | ||
378 | + temp_buffer++; | ||
379 | + /* Strip leading spaces */ | ||
380 | + for (; *temp_buffer != '\0' && *temp_buffer == ' '; temp_buffer++) | ||
381 | + /* NOOP */; | ||
382 | + address = strdup (temp_buffer); | ||
383 | + strip (address); | ||
384 | if (address==NULL || strlen(address)==0) | ||
385 | - terminate (STATE_CRITICAL, | ||
386 | - "DNS CRITICAL - '%s' output parsing exited with no address\n", | ||
387 | - NSLOOKUP_COMMAND); | ||
388 | - | ||
389 | - /* compare to expected address */ | ||
390 | - if (result == STATE_OK && match_expected_address && strcmp(address, expected_address)) { | ||
391 | - result = STATE_CRITICAL; | ||
392 | - asprintf(&output, "expected %s but got %s", expected_address, address); | ||
393 | - } | ||
394 | - | ||
395 | - (void) time (&end_time); | ||
396 | - | ||
397 | - if (result == STATE_OK) | ||
398 | - printf ("DNS ok - %d seconds response time, Address(es) is/are %s\n", | ||
399 | - (int) (end_time - start_time), address); | ||
400 | - else if (result == STATE_WARNING) | ||
401 | - printf ("DNS WARNING - %s\n", | ||
402 | - !strcmp (output, "") ? " Probably a non-existent host/domain" : output); | ||
403 | - else if (result == STATE_CRITICAL) | ||
404 | - printf ("DNS CRITICAL - %s\n", | ||
405 | - !strcmp (output, "") ? " Probably a non-existent host/domain" : output); | ||
406 | - else | ||
407 | - printf ("DNS problem - %s\n", | ||
408 | - !strcmp (output, "") ? " Probably a non-existent host/domain" : output); | ||
409 | - | ||
410 | - return result; | ||
411 | + terminate (STATE_CRITICAL, | ||
412 | + "DNS CRITICAL - '%s' returned empty host name string\n", | ||
413 | + NSLOOKUP_COMMAND); | ||
414 | + result = STATE_OK; | ||
415 | + } | ||
416 | + else { | ||
417 | + output = strdup ("Unknown error (plugin)"); | ||
418 | + result = STATE_WARNING; | ||
419 | + } | ||
420 | + break; | ||
421 | + } | ||
422 | + result = error_scan (input_buffer); | ||
423 | + if (result != STATE_OK) { | ||
424 | + output = strscpy (output, 1 + index (input_buffer, ':')); | ||
425 | + break; | ||
426 | + } | ||
427 | + } | ||
428 | + /* scan stderr */ | ||
429 | + while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { | ||
430 | + if (error_scan (input_buffer) != STATE_OK) { | ||
431 | + result = max (result, error_scan (input_buffer)); | ||
432 | + output = strscpy (output, 1 + index (input_buffer, ':')); | ||
433 | + } | ||
434 | + } | ||
435 | + /* close stderr */ | ||
436 | + (void) fclose (child_stderr); | ||
437 | + /* close stdout */ | ||
438 | + if (spclose (child_process)) { | ||
439 | + result = max_state (result, STATE_WARNING); /* was "max" check for problems */ | ||
440 | + if (!strcmp (output, "")) | ||
441 | + output = strscpy (output, "nslookup returned error status"); | ||
442 | + } | ||
443 | +#endif | ||
444 | + (void) time (&end_time); | ||
445 | + if (address) { | ||
446 | + while (isspace(address[0])) { | ||
447 | + address=&address[1]; | ||
448 | + } | ||
449 | + } | ||
450 | + /* If we got here, we should have an address string, | ||
451 | + and we can segfault if we do not */ | ||
452 | + if (address==NULL || strlen(address)==0) | ||
453 | + terminate (STATE_CRITICAL, | ||
454 | + "DNS CRITICAL - '%s' output parsing exited with no address\n", | ||
455 | + NSLOOKUP_COMMAND); | ||
456 | + /* compare to expected address */ | ||
457 | + if (result == STATE_OK && match_expected_address && strcmp(address, expected_address)) { | ||
458 | + result = STATE_CRITICAL; | ||
459 | + asprintf(&output, "expected %s but got %s", expected_address, address); | ||
460 | + } | ||
461 | + if (result == STATE_OK) | ||
462 | + printf ("DNS ok - %d seconds response time, Address(es) is/are %s\n", | ||
463 | + (int) (end_time - start_time), address); | ||
464 | + else if (result == STATE_WARNING) | ||
465 | + printf ("DNS WARNING - %s\n", | ||
466 | + !strcmp (output, "") ? " Probably a non-existent host/domain" : output); | ||
467 | + else if (result == STATE_CRITICAL) | ||
468 | + printf ("DNS CRITICAL - %s\n", | ||
469 | + !strcmp (output, "") ? " Probably a non-existent host/domain" : output); | ||
470 | + else | ||
471 | + printf ("DNS problem - %s\n", | ||
472 | + !strcmp (output, "") ? " Probably a non-existent host/domain" : output); | ||
473 | + return result; | ||
474 | } | ||
475 | |||
476 | int | ||
477 | @@ -262,6 +436,13 @@ | ||
478 | else if (strstr (input_buffer, "Format error")) | ||
479 | return STATE_WARNING; | ||
480 | |||
481 | + else if (strstr (input_buffer, "No answer")) | ||
482 | + return STATE_WARNING; | ||
483 | + | ||
484 | + /* Server is not authoritative for this question */ | ||
485 | + else if (strstr (input_buffer, "Non-authoritative answer")) | ||
486 | + return STATE_OK; | ||
487 | + | ||
488 | else | ||
489 | return STATE_OK; | ||
490 | |||
491 | @@ -283,7 +464,8 @@ | ||
492 | {"hostname", required_argument, 0, 'H'}, | ||
493 | {"server", required_argument, 0, 's'}, | ||
494 | {"reverse-server", required_argument, 0, 'r'}, | ||
495 | - {"expected-address", required_argument, 0, 'a'}, | ||
496 | + {"expected-answer", required_argument, 0, 'a'}, | ||
497 | + {"resource-record", required_argument, 0, 'T'}, | ||
498 | {0, 0, 0, 0} | ||
499 | }; | ||
500 | #endif | ||
501 | @@ -297,9 +479,9 @@ | ||
502 | |||
503 | while (1) { | ||
504 | #ifdef HAVE_GETOPT_H | ||
505 | - c = getopt_long (argc, argv, "hVvt:H:s:r:a:", long_opts, &opt_index); | ||
506 | + c = getopt_long (argc, argv, "+?hVvt:H:s:r:a:T:", long_opts, &opt_index); | ||
507 | #else | ||
508 | - c = getopt (argc, argv, "hVvt:H:s:r:a:"); | ||
509 | + c = getopt (argc, argv, "+?hVvt:H:s:r:a:T:"); | ||
510 | #endif | ||
511 | |||
512 | if (c == -1 || c == EOF) | ||
513 | @@ -352,17 +534,17 @@ | ||
514 | terminate (STATE_UNKNOWN, "Input buffer overflow\n"); | ||
515 | strcpy (ptr_server, optarg); | ||
516 | break; | ||
517 | - case 'a': /* expected address */ | ||
518 | - if (is_dotted_quad (optarg) == FALSE) { | ||
519 | - printf ("Invalid expected address\n\n"); | ||
520 | - print_usage (); | ||
521 | - exit (STATE_UNKNOWN); | ||
522 | - } | ||
523 | + case 'a': /* expected answer */ | ||
524 | if (strlen (optarg) >= ADDRESS_LENGTH) | ||
525 | terminate (STATE_UNKNOWN, "Input buffer overflow\n"); | ||
526 | strcpy (expected_address, optarg); | ||
527 | match_expected_address = TRUE; | ||
528 | break; | ||
529 | + case 'T': /* Resource record type */ | ||
530 | + if (strlen (optarg) >= RRTYPE_LENGTH) | ||
531 | + terminate (STATE_UNKNOWN, "INput buffer overflow\n"); | ||
532 | + strcpy (record_type, optarg); | ||
533 | + break; | ||
534 | } | ||
535 | } | ||
536 | |||
537 | @@ -402,8 +584,10 @@ | ||
538 | void | ||
539 | print_usage (void) | ||
540 | { | ||
541 | - printf ("Usage: %s -H host [-s server] [-a expected-address] [-t timeout]\n" " %s --help\n" | ||
542 | - " %s --version\n", progname, progname, progname); | ||
543 | + printf ("Usage: %s -H host [-s server] [-r reverse-server] [-t timeout] [-T querytype] [-a answer]\n" | ||
544 | + " %s --help\n" | ||
545 | + " %s --version\n", | ||
546 | + progname, progname, progname); | ||
547 | } | ||
548 | |||
549 | void | ||
550 | @@ -418,16 +602,28 @@ | ||
551 | " The name or address you want to query\n" | ||
552 | "-s, --server=HOST\n" | ||
553 | " Optional DNS server you want to use for the lookup\n" | ||
554 | - "-a, --expected-address=IP-ADDRESS\n" | ||
555 | - " Optional IP address you expect the DNS server to return\n" | ||
556 | + "-r, --reverse-server=HOST\n" | ||
557 | + " Optional DNS server to do PTR lookup - NOT IMPLEMENTED\n" | ||
558 | "-t, --timeout=INTEGER\n" | ||
559 | " Seconds before connection times out (default: %d)\n" | ||
560 | + "-T, --resource-record=QUERYTYPE\n" | ||
561 | + " Type of query to issue - default is A - [A,CNAME,HINFO,MINFO,MX,NS,PTR,SOA,TXT,UINFO,WKS,ANY]\n" | ||
562 | + "-a, --expected-answer=STRING\n" | ||
563 | + " String to match from server as answer - be very careful how you specify this\n" | ||
564 | "-h, --help\n" | ||
565 | " Print detailed help\n" | ||
566 | "-V, --version\n" | ||
567 | " Print version numbers and license information\n" | ||
568 | "\n" | ||
569 | +#ifdef USE_NSLOOKUP | ||
570 | "This plugin uses the nslookup program to obtain the IP address\n" | ||
571 | +#endif | ||
572 | +#ifdef USE_HOST | ||
573 | + "This plugin uses the host program to obtain the IP address\n" | ||
574 | +#endif | ||
575 | +#ifdef USE_RESOLVER | ||
576 | + "This plugin uses the resolver library to obtain the IP address\n" | ||
577 | +#endif | ||
578 | "for the given host/domain query. A optional DNS server to use may\n" | ||
579 | "be specified. If no DNS server is specified, the default server(s)\n" | ||
580 | "specified in /etc/resolv.conf will be used.\n", DEFAULT_SOCKET_TIMEOUT); | ||
581 | diff -ruN nagios-plugins-1.3.1/plugins/check_tcp.c nagios-plugins-1.3.1-new/plugins/check_tcp.c | ||
582 | --- nagios-plugins-1.3.1/plugins/check_tcp.c 2003-06-10 05:56:47.000000000 +0100 | ||
583 | +++ nagios-plugins-1.3.1-new/plugins/check_tcp.c 2003-07-14 18:39:57.000000000 +0100 | ||
584 | @@ -67,7 +67,7 @@ | ||
585 | void print_usage (void); | ||
586 | void print_help (void); | ||
587 | int my_recv (void); | ||
588 | - | ||
589 | +int check_expect(char *); | ||
590 | char *progname = "check_tcp"; | ||
591 | char *SERVICE = NULL; | ||
592 | char *SEND = NULL; | ||
593 | @@ -259,6 +259,7 @@ | ||
594 | while ((i = my_recv ()) > 0) { | ||
595 | buffer[i] = '\0'; | ||
596 | asprintf (&status, "%s%s", status, buffer); | ||
597 | + if (server_expect_count > 0 && check_expect(status)) break; | ||
598 | if (buffer[i-2] == '\r' && buffer[i-1] == '\n') | ||
599 | break; | ||
600 | if (maxbytes>0 && strlen(status)>=maxbytes) | ||
601 | @@ -274,16 +275,11 @@ | ||
602 | if (status && verbose) | ||
603 | printf ("%s\n", status); | ||
604 | |||
605 | + /* - does not do anything!! | ||
606 | if (server_expect_count > 0) { | ||
607 | - for (i = 0;; i++) { | ||
608 | - if (verbose) | ||
609 | - printf ("%d %d\n", i, server_expect_count); | ||
610 | - if (i >= server_expect_count) | ||
611 | - terminate (STATE_WARNING, "Invalid response from host\n"); | ||
612 | - if (strstr (status, server_expect[i])) | ||
613 | - break; | ||
614 | - } | ||
615 | + check_expect(status); | ||
616 | } | ||
617 | + */ | ||
618 | } | ||
619 | |||
620 | if (server_quit != NULL) | ||
621 | @@ -608,10 +604,24 @@ | ||
622 | } | ||
623 | else { | ||
624 | #endif | ||
625 | - i = read (sd, buffer, MAXBUF - 1); | ||
626 | + i = recv (sd, buffer, MAXBUF - 1, 0); | ||
627 | #ifdef HAVE_SSL | ||
628 | } | ||
629 | #endif | ||
630 | |||
631 | return i; | ||
632 | } | ||
633 | + | ||
634 | +int check_expect(char * status) { | ||
635 | + int i; | ||
636 | + | ||
637 | + for (i = 0;; i++) { | ||
638 | + if (verbose) | ||
639 | + printf ("%d %d\n", i, server_expect_count); | ||
640 | + if (i >= server_expect_count) | ||
641 | + terminate (STATE_WARNING, "Invalid response from host\n"); | ||
642 | + if (strstr (status, server_expect[i])) | ||
643 | + return TRUE; | ||
644 | + } | ||
645 | + return FALSE; | ||
646 | +} | ||