diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-07-31 12:06:38 +0000 |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-07-31 12:06:38 +0000 |
commit | c4361620a0596945d3b438f9351122970fa7ab53 (patch) | |
tree | 9ae97512b3faf980547581637a6f58b2be3fd5ca /plugins/check_dns.c | |
parent | f66c7492f52c7750dedcd0365bd313db19cfaea5 (diff) | |
download | monitoring-plugins-c4361620a0596945d3b438f9351122970fa7ab53.tar.gz |
mark for translation (note problem here - it relies on tranalation in underlying utility, which has a high chance of failing)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@623 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_dns.c')
-rw-r--r-- | plugins/check_dns.c | 171 |
1 files changed, 86 insertions, 85 deletions
diff --git a/plugins/check_dns.c b/plugins/check_dns.c index f1071d8e..d7546106 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c | |||
@@ -47,15 +47,53 @@ | |||
47 | #include "common.h" | 47 | #include "common.h" |
48 | #include "popen.h" | 48 | #include "popen.h" |
49 | #include "utils.h" | 49 | #include "utils.h" |
50 | #include "netutils.h" | ||
50 | 51 | ||
51 | const char *progname = "check_dns"; | 52 | const char *progname = "check_dns"; |
52 | #define REVISION "$Revision$" | 53 | const char *revision = "$Revision$"; |
53 | #define COPYRIGHT "2000-2002" | 54 | const char *copyright = "2000-2003"; |
55 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | ||
56 | |||
57 | void | ||
58 | print_usage (void) | ||
59 | { | ||
60 | printf (_("\ | ||
61 | Usage: %s -H host [-s server] [-a expected-address] [-t timeout]\n\ | ||
62 | %s --help\n\ | ||
63 | %s --version\n"), | ||
64 | progname, progname, progname); | ||
65 | } | ||
66 | |||
67 | void | ||
68 | print_help (void) | ||
69 | { | ||
70 | print_revision (progname, revision); | ||
71 | |||
72 | printf (_(COPYRIGHT), copyright, email); | ||
73 | |||
74 | print_usage (); | ||
75 | |||
76 | printf (_(HELP_VRSN)); | ||
77 | |||
78 | printf (_("\ | ||
79 | -H, --hostname=HOST\n\ | ||
80 | The name or address you want to query\n\ | ||
81 | -s, --server=HOST\n\ | ||
82 | Optional DNS server you want to use for the lookup\n\ | ||
83 | -a, --expected-address=IP-ADDRESS\n\ | ||
84 | Optional IP address you expect the DNS server to return\n")); | ||
85 | |||
86 | printf (_(TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
87 | |||
88 | printf (_("\n\ | ||
89 | This plugin uses the nslookup program to obtain the IP address\n\ | ||
90 | for the given host/domain query. A optional DNS server to use may\n\ | ||
91 | be specified. If no DNS server is specified, the default server(s)\n\ | ||
92 | specified in /etc/resolv.conf will be used.\n")); | ||
93 | } | ||
54 | 94 | ||
55 | int process_arguments (int, char **); | 95 | int process_arguments (int, char **); |
56 | int validate_arguments (void); | 96 | int validate_arguments (void); |
57 | void print_usage (void); | ||
58 | void print_help (void); | ||
59 | int error_scan (char *); | 97 | int error_scan (char *); |
60 | 98 | ||
61 | #define ADDRESS_LENGTH 256 | 99 | #define ADDRESS_LENGTH 256 |
@@ -81,7 +119,7 @@ main (int argc, char **argv) | |||
81 | 119 | ||
82 | /* Set signal handling and alarm */ | 120 | /* Set signal handling and alarm */ |
83 | if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { | 121 | if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { |
84 | printf ("Cannot catch SIGALRM"); | 122 | printf (_("Cannot catch SIGALRM")); |
85 | return STATE_UNKNOWN; | 123 | return STATE_UNKNOWN; |
86 | } | 124 | } |
87 | 125 | ||
@@ -101,13 +139,13 @@ main (int argc, char **argv) | |||
101 | /* run the command */ | 139 | /* run the command */ |
102 | child_process = spopen (command_line); | 140 | child_process = spopen (command_line); |
103 | if (child_process == NULL) { | 141 | if (child_process == NULL) { |
104 | printf ("Could not open pipe: %s\n", command_line); | 142 | printf (_("Could not open pipe: %s\n"), command_line); |
105 | return STATE_UNKNOWN; | 143 | return STATE_UNKNOWN; |
106 | } | 144 | } |
107 | 145 | ||
108 | child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); | 146 | child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); |
109 | if (child_stderr == NULL) | 147 | if (child_stderr == NULL) |
110 | printf ("Could not open stderr for %s\n", command_line); | 148 | printf (_("Could not open stderr for %s\n"), command_line); |
111 | 149 | ||
112 | /* scan stdout */ | 150 | /* scan stdout */ |
113 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { | 151 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { |
@@ -119,7 +157,7 @@ main (int argc, char **argv) | |||
119 | if ((temp_buffer = strstr (input_buffer, "name = "))) | 157 | if ((temp_buffer = strstr (input_buffer, "name = "))) |
120 | address = strscpy (address, temp_buffer + 7); | 158 | address = strscpy (address, temp_buffer + 7); |
121 | else { | 159 | else { |
122 | output = strscpy (output, "Unknown error (plugin)"); | 160 | output = strscpy (output, _("Unknown error (plugin)")); |
123 | result = STATE_WARNING; | 161 | result = STATE_WARNING; |
124 | } | 162 | } |
125 | } | 163 | } |
@@ -143,12 +181,12 @@ main (int argc, char **argv) | |||
143 | strip (address); | 181 | strip (address); |
144 | if (address==NULL || strlen(address)==0) | 182 | if (address==NULL || strlen(address)==0) |
145 | terminate (STATE_CRITICAL, | 183 | terminate (STATE_CRITICAL, |
146 | "DNS CRITICAL - '%s' returned empty host name string\n", | 184 | _("DNS CRITICAL - '%s' returned empty host name string\n"), |
147 | NSLOOKUP_COMMAND); | 185 | NSLOOKUP_COMMAND); |
148 | result = STATE_OK; | 186 | result = STATE_OK; |
149 | } | 187 | } |
150 | else { | 188 | else { |
151 | output = strdup ("Unknown error (plugin)"); | 189 | output = strdup (_("Unknown error (plugin)")); |
152 | result = STATE_WARNING; | 190 | result = STATE_WARNING; |
153 | } | 191 | } |
154 | 192 | ||
@@ -180,20 +218,20 @@ main (int argc, char **argv) | |||
180 | if (spclose (child_process)) { | 218 | if (spclose (child_process)) { |
181 | result = max_state (result, STATE_WARNING); | 219 | result = max_state (result, STATE_WARNING); |
182 | if (!strcmp (output, "")) | 220 | if (!strcmp (output, "")) |
183 | output = strscpy (output, "nslookup returned error status"); | 221 | output = strscpy (output, _("nslookup returned error status")); |
184 | } | 222 | } |
185 | 223 | ||
186 | /* If we got here, we should have an address string, | 224 | /* If we got here, we should have an address string, |
187 | and we can segfault if we do not */ | 225 | and we can segfault if we do not */ |
188 | if (address==NULL || strlen(address)==0) | 226 | if (address==NULL || strlen(address)==0) |
189 | terminate (STATE_CRITICAL, | 227 | terminate (STATE_CRITICAL, |
190 | "DNS CRITICAL - '%s' output parsing exited with no address\n", | 228 | _("DNS CRITICAL - '%s' output parsing exited with no address\n"), |
191 | NSLOOKUP_COMMAND); | 229 | NSLOOKUP_COMMAND); |
192 | 230 | ||
193 | /* compare to expected address */ | 231 | /* compare to expected address */ |
194 | if (result == STATE_OK && match_expected_address && strcmp(address, expected_address)) { | 232 | if (result == STATE_OK && match_expected_address && strcmp(address, expected_address)) { |
195 | result = STATE_CRITICAL; | 233 | result = STATE_CRITICAL; |
196 | asprintf(&output, "expected %s but got %s", expected_address, address); | 234 | asprintf(&output, _("expected %s but got %s"), expected_address, address); |
197 | } | 235 | } |
198 | 236 | ||
199 | elapsed_time = delta_time (tv); | 237 | elapsed_time = delta_time (tv); |
@@ -204,18 +242,18 @@ main (int argc, char **argv) | |||
204 | else | 242 | else |
205 | multi_address = TRUE; | 243 | multi_address = TRUE; |
206 | 244 | ||
207 | printf ("DNS ok - %.3f seconds response time, address%s %s|time=%.3f\n", | 245 | printf (_("DNS ok - %.3f seconds response time, address%s %s|time=%.3f\n"), |
208 | elapsed_time, (multi_address==TRUE ? "es are" : " is"), address, elapsed_time); | 246 | elapsed_time, (multi_address==TRUE ? "es are" : " is"), address, elapsed_time); |
209 | } | 247 | } |
210 | else if (result == STATE_WARNING) | 248 | else if (result == STATE_WARNING) |
211 | printf ("DNS WARNING - %s\n", | 249 | printf (_("DNS WARNING - %s\n"), |
212 | !strcmp (output, "") ? " Probably a non-existent host/domain" : output); | 250 | !strcmp (output, "") ? _(" Probably a non-existent host/domain") : output); |
213 | else if (result == STATE_CRITICAL) | 251 | else if (result == STATE_CRITICAL) |
214 | printf ("DNS CRITICAL - %s\n", | 252 | printf (_("DNS CRITICAL - %s\n"), |
215 | !strcmp (output, "") ? " Probably a non-existent host/domain" : output); | 253 | !strcmp (output, "") ? _(" Probably a non-existent host/domain") : output); |
216 | else | 254 | else |
217 | printf ("DNS problem - %s\n", | 255 | printf (_("DNS problem - %s\n"), |
218 | !strcmp (output, "") ? " Probably a non-existent host/domain" : output); | 256 | !strcmp (output, "") ? _(" Probably a non-existent host/domain") : output); |
219 | 257 | ||
220 | return result; | 258 | return result; |
221 | } | 259 | } |
@@ -225,52 +263,49 @@ error_scan (char *input_buffer) | |||
225 | { | 263 | { |
226 | 264 | ||
227 | /* the DNS lookup timed out */ | 265 | /* the DNS lookup timed out */ |
228 | if (strstr (input_buffer, | 266 | if (strstr (input_buffer, _("Note: nslookup is deprecated and may be removed from future releases.")) || |
229 | "Note: nslookup is deprecated and may be removed from future releases.") | 267 | strstr (input_buffer, _("Consider using the `dig' or `host' programs instead. Run nslookup with")) || |
230 | || strstr (input_buffer, | 268 | strstr (input_buffer, _("the `-sil[ent]' option to prevent this message from appearing."))) |
231 | "Consider using the `dig' or `host' programs instead. Run nslookup with") | ||
232 | || strstr (input_buffer, | ||
233 | "the `-sil[ent]' option to prevent this message from appearing.")) | ||
234 | return STATE_OK; | 269 | return STATE_OK; |
235 | 270 | ||
236 | /* the DNS lookup timed out */ | 271 | /* the DNS lookup timed out */ |
237 | else if (strstr (input_buffer, "Timed out")) | 272 | else if (strstr (input_buffer, _("Timed out"))) |
238 | return STATE_WARNING; | 273 | return STATE_WARNING; |
239 | 274 | ||
240 | /* DNS server is not running... */ | 275 | /* DNS server is not running... */ |
241 | else if (strstr (input_buffer, "No response from server")) | 276 | else if (strstr (input_buffer, _("No response from server"))) |
242 | return STATE_CRITICAL; | 277 | return STATE_CRITICAL; |
243 | 278 | ||
244 | /* Host name is valid, but server doesn't have records... */ | 279 | /* Host name is valid, but server doesn't have records... */ |
245 | else if (strstr (input_buffer, "No records")) | 280 | else if (strstr (input_buffer, _("No records"))) |
246 | return STATE_WARNING; | 281 | return STATE_WARNING; |
247 | 282 | ||
248 | /* Host or domain name does not exist */ | 283 | /* Host or domain name does not exist */ |
249 | else if (strstr (input_buffer, "Non-existent")) | 284 | else if (strstr (input_buffer, _("Non-existent"))) |
250 | return STATE_CRITICAL; | 285 | return STATE_CRITICAL; |
251 | else if (strstr (input_buffer, "** server can't find")) | 286 | else if (strstr (input_buffer, _("** server can't find"))) |
252 | return STATE_CRITICAL; | 287 | return STATE_CRITICAL; |
253 | else if(strstr(input_buffer,"NXDOMAIN")) /* 9.x */ | 288 | else if(strstr(input_buffer,"NXDOMAIN")) /* 9.x */ |
254 | return STATE_CRITICAL; | 289 | return STATE_CRITICAL; |
255 | 290 | ||
256 | /* Connection was refused */ | 291 | /* Connection was refused */ |
257 | else if (strstr (input_buffer, "Connection refused")) | 292 | else if (strstr (input_buffer, _("Connection refused"))) |
258 | return STATE_CRITICAL; | 293 | return STATE_CRITICAL; |
259 | 294 | ||
260 | /* Network is unreachable */ | 295 | /* Network is unreachable */ |
261 | else if (strstr (input_buffer, "Network is unreachable")) | 296 | else if (strstr (input_buffer, _("Network is unreachable"))) |
262 | return STATE_CRITICAL; | 297 | return STATE_CRITICAL; |
263 | 298 | ||
264 | /* Internal server failure */ | 299 | /* Internal server failure */ |
265 | else if (strstr (input_buffer, "Server failure")) | 300 | else if (strstr (input_buffer, _("Server failure"))) |
266 | return STATE_CRITICAL; | 301 | return STATE_CRITICAL; |
267 | 302 | ||
268 | /* DNS server refused to service request */ | 303 | /* DNS server refused to service request */ |
269 | else if (strstr (input_buffer, "Refused")) | 304 | else if (strstr (input_buffer, _("Refused"))) |
270 | return STATE_CRITICAL; | 305 | return STATE_CRITICAL; |
271 | 306 | ||
272 | /* Request error */ | 307 | /* Request error */ |
273 | else if (strstr (input_buffer, "Format error")) | 308 | else if (strstr (input_buffer, _("Format error"))) |
274 | return STATE_WARNING; | 309 | return STATE_WARNING; |
275 | 310 | ||
276 | else | 311 | else |
@@ -312,14 +347,14 @@ process_arguments (int argc, char **argv) | |||
312 | 347 | ||
313 | switch (c) { | 348 | switch (c) { |
314 | case '?': /* args not parsable */ | 349 | case '?': /* args not parsable */ |
315 | printf ("%s: Unknown argument: %s\n\n", progname, optarg); | 350 | printf (_("%s: Unknown argument: %s\n\n"), progname, optarg); |
316 | print_usage (); | 351 | print_usage (); |
317 | exit (STATE_UNKNOWN); | 352 | exit (STATE_UNKNOWN); |
318 | case 'h': /* help */ | 353 | case 'h': /* help */ |
319 | print_help (); | 354 | print_help (); |
320 | exit (STATE_OK); | 355 | exit (STATE_OK); |
321 | case 'V': /* version */ | 356 | case 'V': /* version */ |
322 | print_revision (progname, REVISION); | 357 | print_revision (progname, revision); |
323 | exit (STATE_OK); | 358 | exit (STATE_OK); |
324 | case 'v': /* version */ | 359 | case 'v': /* version */ |
325 | verbose = TRUE; | 360 | verbose = TRUE; |
@@ -329,35 +364,35 @@ process_arguments (int argc, char **argv) | |||
329 | break; | 364 | break; |
330 | case 'H': /* hostname */ | 365 | case 'H': /* hostname */ |
331 | if (strlen (optarg) >= ADDRESS_LENGTH) | 366 | if (strlen (optarg) >= ADDRESS_LENGTH) |
332 | terminate (STATE_UNKNOWN, "Input buffer overflow\n"); | 367 | terminate (STATE_UNKNOWN, _("Input buffer overflow\n")); |
333 | strcpy (query_address, optarg); | 368 | strcpy (query_address, optarg); |
334 | break; | 369 | break; |
335 | case 's': /* server name */ | 370 | case 's': /* server name */ |
336 | /* TODO: this is_host check is probably unnecessary. Better to confirm nslookup | 371 | /* TODO: this is_host check is probably unnecessary. Better to confirm nslookup |
337 | response matches */ | 372 | response matches */ |
338 | if (is_host (optarg) == FALSE) { | 373 | if (is_host (optarg) == FALSE) { |
339 | printf ("Invalid server name/address\n\n"); | 374 | printf (_("Invalid server name/address\n\n")); |
340 | print_usage (); | 375 | print_usage (); |
341 | exit (STATE_UNKNOWN); | 376 | exit (STATE_UNKNOWN); |
342 | } | 377 | } |
343 | if (strlen (optarg) >= ADDRESS_LENGTH) | 378 | if (strlen (optarg) >= ADDRESS_LENGTH) |
344 | terminate (STATE_UNKNOWN, "Input buffer overflow\n"); | 379 | terminate (STATE_UNKNOWN, _("Input buffer overflow\n")); |
345 | strcpy (dns_server, optarg); | 380 | strcpy (dns_server, optarg); |
346 | break; | 381 | break; |
347 | case 'r': /* reverse server name */ | 382 | case 'r': /* reverse server name */ |
348 | /* TODO: Is this is_host necessary? */ | 383 | /* TODO: Is this is_host necessary? */ |
349 | if (is_host (optarg) == FALSE) { | 384 | if (is_host (optarg) == FALSE) { |
350 | printf ("Invalid host name/address\n\n"); | 385 | printf (_("Invalid host name/address\n\n")); |
351 | print_usage (); | 386 | print_usage (); |
352 | exit (STATE_UNKNOWN); | 387 | exit (STATE_UNKNOWN); |
353 | } | 388 | } |
354 | if (strlen (optarg) >= ADDRESS_LENGTH) | 389 | if (strlen (optarg) >= ADDRESS_LENGTH) |
355 | terminate (STATE_UNKNOWN, "Input buffer overflow\n"); | 390 | terminate (STATE_UNKNOWN, _("Input buffer overflow\n")); |
356 | strcpy (ptr_server, optarg); | 391 | strcpy (ptr_server, optarg); |
357 | break; | 392 | break; |
358 | case 'a': /* expected address */ | 393 | case 'a': /* expected address */ |
359 | if (strlen (optarg) >= ADDRESS_LENGTH) | 394 | if (strlen (optarg) >= ADDRESS_LENGTH) |
360 | terminate (STATE_UNKNOWN, "Input buffer overflow\n"); | 395 | terminate (STATE_UNKNOWN, _("Input buffer overflow\n")); |
361 | strcpy (expected_address, optarg); | 396 | strcpy (expected_address, optarg); |
362 | match_expected_address = TRUE; | 397 | match_expected_address = TRUE; |
363 | break; | 398 | break; |
@@ -367,18 +402,18 @@ process_arguments (int argc, char **argv) | |||
367 | c = optind; | 402 | c = optind; |
368 | if (strlen(query_address)==0 && c<argc) { | 403 | if (strlen(query_address)==0 && c<argc) { |
369 | if (strlen(argv[c])>=ADDRESS_LENGTH) | 404 | if (strlen(argv[c])>=ADDRESS_LENGTH) |
370 | terminate (STATE_UNKNOWN, "Input buffer overflow\n"); | 405 | terminate (STATE_UNKNOWN, _("Input buffer overflow\n")); |
371 | strcpy (query_address, argv[c++]); | 406 | strcpy (query_address, argv[c++]); |
372 | } | 407 | } |
373 | 408 | ||
374 | if (strlen(dns_server)==0 && c<argc) { | 409 | if (strlen(dns_server)==0 && c<argc) { |
375 | /* TODO: See -s option */ | 410 | /* TODO: See -s option */ |
376 | if (is_host(argv[c]) == FALSE) { | 411 | if (is_host(argv[c]) == FALSE) { |
377 | printf ("Invalid name/address: %s\n\n", argv[c]); | 412 | printf (_("Invalid name/address: %s\n\n"), argv[c]); |
378 | return ERROR; | 413 | return ERROR; |
379 | } | 414 | } |
380 | if (strlen(argv[c]) >= ADDRESS_LENGTH) | 415 | if (strlen(argv[c]) >= ADDRESS_LENGTH) |
381 | terminate (STATE_UNKNOWN, "Input buffer overflow\n"); | 416 | terminate (STATE_UNKNOWN, _("Input buffer overflow\n")); |
382 | strcpy (dns_server, argv[c++]); | 417 | strcpy (dns_server, argv[c++]); |
383 | } | 418 | } |
384 | 419 | ||
@@ -393,37 +428,3 @@ validate_arguments () | |||
393 | else | 428 | else |
394 | return OK; | 429 | return OK; |
395 | } | 430 | } |
396 | |||
397 | void | ||
398 | print_usage (void) | ||
399 | { | ||
400 | printf ("Usage: %s -H host [-s server] [-a expected-address] [-t timeout]\n" " %s --help\n" | ||
401 | " %s --version\n", progname, progname, progname); | ||
402 | } | ||
403 | |||
404 | void | ||
405 | print_help (void) | ||
406 | { | ||
407 | print_revision (progname, REVISION); | ||
408 | printf ("Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)\n\n"); | ||
409 | print_usage (); | ||
410 | printf | ||
411 | ("\nOptions:\n" | ||
412 | "-H, --hostname=HOST\n" | ||
413 | " The name or address you want to query\n" | ||
414 | "-s, --server=HOST\n" | ||
415 | " Optional DNS server you want to use for the lookup\n" | ||
416 | "-a, --expected-address=IP-ADDRESS\n" | ||
417 | " Optional IP address you expect the DNS server to return\n" | ||
418 | "-t, --timeout=INTEGER\n" | ||
419 | " Seconds before connection times out (default: %d)\n" | ||
420 | "-h, --help\n" | ||
421 | " Print detailed help\n" | ||
422 | "-V, --version\n" | ||
423 | " Print version numbers and license information\n" | ||
424 | "\n" | ||
425 | "This plugin uses the nslookup program to obtain the IP address\n" | ||
426 | "for the given host/domain query. A optional DNS server to use may\n" | ||
427 | "be specified. If no DNS server is specified, the default server(s)\n" | ||
428 | "specified in /etc/resolv.conf will be used.\n", DEFAULT_SOCKET_TIMEOUT); | ||
429 | } | ||