diff options
-rw-r--r-- | plugins/check_dns.c | 65 |
1 files changed, 32 insertions, 33 deletions
diff --git a/plugins/check_dns.c b/plugins/check_dns.c index 7ffce98b..7dcec384 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c | |||
@@ -41,8 +41,8 @@ const char *email = "devel@monitoring-plugins.org"; | |||
41 | 41 | ||
42 | int process_arguments (int, char **); | 42 | int process_arguments (int, char **); |
43 | int validate_arguments (void); | 43 | int validate_arguments (void); |
44 | int error_scan (char *, int *); | 44 | int error_scan (char *, bool *); |
45 | int ip_match_cidr(const char *, const char *); | 45 | bool ip_match_cidr(const char *, const char *); |
46 | unsigned long ip2long(const char *); | 46 | unsigned long ip2long(const char *); |
47 | void print_help (void); | 47 | void print_help (void); |
48 | void print_usage (void); | 48 | void print_usage (void); |
@@ -51,13 +51,13 @@ void print_usage (void); | |||
51 | char query_address[ADDRESS_LENGTH] = ""; | 51 | char query_address[ADDRESS_LENGTH] = ""; |
52 | char dns_server[ADDRESS_LENGTH] = ""; | 52 | char dns_server[ADDRESS_LENGTH] = ""; |
53 | char ptr_server[ADDRESS_LENGTH] = ""; | 53 | char ptr_server[ADDRESS_LENGTH] = ""; |
54 | int verbose = FALSE; | 54 | bool verbose = false; |
55 | char **expected_address = NULL; | 55 | char **expected_address = NULL; |
56 | int expected_address_cnt = 0; | 56 | int expected_address_cnt = 0; |
57 | int expect_nxdomain = FALSE; | 57 | bool expect_nxdomain = false; |
58 | 58 | ||
59 | int expect_authority = FALSE; | 59 | bool expect_authority = false; |
60 | int all_match = FALSE; | 60 | bool all_match = false; |
61 | thresholds *time_thresholds = NULL; | 61 | thresholds *time_thresholds = NULL; |
62 | 62 | ||
63 | static int | 63 | static int |
@@ -80,15 +80,15 @@ main (int argc, char **argv) | |||
80 | int n_addresses = 0; | 80 | int n_addresses = 0; |
81 | char *msg = NULL; | 81 | char *msg = NULL; |
82 | char *temp_buffer = NULL; | 82 | char *temp_buffer = NULL; |
83 | int non_authoritative = FALSE; | 83 | bool non_authoritative = false; |
84 | int result = STATE_UNKNOWN; | 84 | int result = STATE_UNKNOWN; |
85 | double elapsed_time; | 85 | double elapsed_time; |
86 | long microsec; | 86 | long microsec; |
87 | struct timeval tv; | 87 | struct timeval tv; |
88 | int parse_address = FALSE; /* This flag scans for Address: but only after Name: */ | 88 | bool parse_address = false; /* This flag scans for Address: but only after Name: */ |
89 | output chld_out, chld_err; | 89 | output chld_out, chld_err; |
90 | size_t i; | 90 | size_t i; |
91 | int is_nxdomain = FALSE; | 91 | int is_nxdomain = false; |
92 | 92 | ||
93 | setlocale (LC_ALL, ""); | 93 | setlocale (LC_ALL, ""); |
94 | bindtextdomain (PACKAGE, LOCALEDIR); | 94 | bindtextdomain (PACKAGE, LOCALEDIR); |
@@ -164,8 +164,8 @@ main (int argc, char **argv) | |||
164 | 164 | ||
165 | /* the server is responding, we just got the host name... */ | 165 | /* the server is responding, we just got the host name... */ |
166 | if (strstr (chld_out.line[i], "Name:")) | 166 | if (strstr (chld_out.line[i], "Name:")) |
167 | parse_address = TRUE; | 167 | parse_address = true; |
168 | else if (parse_address == TRUE && (strstr (chld_out.line[i], "Address:") || | 168 | else if (parse_address && (strstr (chld_out.line[i], "Address:") || |
169 | strstr (chld_out.line[i], "Addresses:"))) { | 169 | strstr (chld_out.line[i], "Addresses:"))) { |
170 | temp_buffer = index (chld_out.line[i], ':'); | 170 | temp_buffer = index (chld_out.line[i], ':'); |
171 | temp_buffer++; | 171 | temp_buffer++; |
@@ -184,7 +184,7 @@ main (int argc, char **argv) | |||
184 | addresses[n_addresses++] = strdup(temp_buffer); | 184 | addresses[n_addresses++] = strdup(temp_buffer); |
185 | } | 185 | } |
186 | else if (strstr (chld_out.line[i], _("Non-authoritative answer:"))) { | 186 | else if (strstr (chld_out.line[i], _("Non-authoritative answer:"))) { |
187 | non_authoritative = TRUE; | 187 | non_authoritative = true; |
188 | } | 188 | } |
189 | 189 | ||
190 | 190 | ||
@@ -298,21 +298,21 @@ main (int argc, char **argv) | |||
298 | printf (_(". %s returns %s"), query_address, address); | 298 | printf (_(". %s returns %s"), query_address, address); |
299 | if ((time_thresholds->warning != NULL) && (time_thresholds->critical != NULL)) { | 299 | if ((time_thresholds->warning != NULL) && (time_thresholds->critical != NULL)) { |
300 | printf ("|%s\n", fperfdata ("time", elapsed_time, "s", | 300 | printf ("|%s\n", fperfdata ("time", elapsed_time, "s", |
301 | TRUE, time_thresholds->warning->end, | 301 | true, time_thresholds->warning->end, |
302 | TRUE, time_thresholds->critical->end, | 302 | true, time_thresholds->critical->end, |
303 | TRUE, 0, FALSE, 0)); | 303 | true, 0, false, 0)); |
304 | } else if ((time_thresholds->warning == NULL) && (time_thresholds->critical != NULL)) { | 304 | } else if ((time_thresholds->warning == NULL) && (time_thresholds->critical != NULL)) { |
305 | printf ("|%s\n", fperfdata ("time", elapsed_time, "s", | 305 | printf ("|%s\n", fperfdata ("time", elapsed_time, "s", |
306 | FALSE, 0, | 306 | false, 0, |
307 | TRUE, time_thresholds->critical->end, | 307 | true, time_thresholds->critical->end, |
308 | TRUE, 0, FALSE, 0)); | 308 | true, 0, false, 0)); |
309 | } else if ((time_thresholds->warning != NULL) && (time_thresholds->critical == NULL)) { | 309 | } else if ((time_thresholds->warning != NULL) && (time_thresholds->critical == NULL)) { |
310 | printf ("|%s\n", fperfdata ("time", elapsed_time, "s", | 310 | printf ("|%s\n", fperfdata ("time", elapsed_time, "s", |
311 | TRUE, time_thresholds->warning->end, | 311 | true, time_thresholds->warning->end, |
312 | FALSE, 0, | 312 | false, 0, |
313 | TRUE, 0, FALSE, 0)); | 313 | true, 0, false, 0)); |
314 | } else | 314 | } else |
315 | printf ("|%s\n", fperfdata ("time", elapsed_time, "s", FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); | 315 | printf ("|%s\n", fperfdata ("time", elapsed_time, "s", false, 0, false, 0, true, 0, false, 0)); |
316 | } | 316 | } |
317 | else if (result == STATE_WARNING) | 317 | else if (result == STATE_WARNING) |
318 | printf (_("DNS WARNING - %s\n"), | 318 | printf (_("DNS WARNING - %s\n"), |
@@ -327,15 +327,14 @@ main (int argc, char **argv) | |||
327 | return result; | 327 | return result; |
328 | } | 328 | } |
329 | 329 | ||
330 | int | 330 | bool ip_match_cidr(const char *addr, const char *cidr_ro) { |
331 | ip_match_cidr(const char *addr, const char *cidr_ro) | ||
332 | { | ||
333 | char *subnet, *mask_c, *cidr = strdup(cidr_ro); | 331 | char *subnet, *mask_c, *cidr = strdup(cidr_ro); |
334 | int mask; | 332 | int mask; |
335 | subnet = strtok(cidr, "/"); | 333 | subnet = strtok(cidr, "/"); |
336 | mask_c = strtok(NULL, "\0"); | 334 | mask_c = strtok(NULL, "\0"); |
337 | if (!subnet || !mask_c) | 335 | if (!subnet || !mask_c) { |
338 | return FALSE; | 336 | return false; |
337 | } | ||
339 | mask = atoi(mask_c); | 338 | mask = atoi(mask_c); |
340 | 339 | ||
341 | /* https://www.cryptobells.com/verifying-ips-in-a-subnet-in-php/ */ | 340 | /* https://www.cryptobells.com/verifying-ips-in-a-subnet-in-php/ */ |
@@ -355,14 +354,14 @@ ip2long(const char* src) { | |||
355 | } | 354 | } |
356 | 355 | ||
357 | int | 356 | int |
358 | error_scan (char *input_buffer, int *is_nxdomain) | 357 | error_scan (char *input_buffer, bool *is_nxdomain) |
359 | { | 358 | { |
360 | 359 | ||
361 | const int nxdomain = strstr (input_buffer, "Non-existent") || | 360 | const int nxdomain = strstr (input_buffer, "Non-existent") || |
362 | strstr (input_buffer, "** server can't find") || | 361 | strstr (input_buffer, "** server can't find") || |
363 | strstr (input_buffer, "** Can't find") || | 362 | strstr (input_buffer, "** Can't find") || |
364 | strstr (input_buffer, "NXDOMAIN"); | 363 | strstr (input_buffer, "NXDOMAIN"); |
365 | if (nxdomain) *is_nxdomain = TRUE; | 364 | if (nxdomain) *is_nxdomain = true; |
366 | 365 | ||
367 | /* the DNS lookup timed out */ | 366 | /* the DNS lookup timed out */ |
368 | if (strstr (input_buffer, _("Note: nslookup is deprecated and may be removed from future releases.")) || | 367 | if (strstr (input_buffer, _("Note: nslookup is deprecated and may be removed from future releases.")) || |
@@ -461,7 +460,7 @@ process_arguments (int argc, char **argv) | |||
461 | print_revision (progname, NP_VERSION); | 460 | print_revision (progname, NP_VERSION); |
462 | exit (STATE_UNKNOWN); | 461 | exit (STATE_UNKNOWN); |
463 | case 'v': /* version */ | 462 | case 'v': /* version */ |
464 | verbose = TRUE; | 463 | verbose = true; |
465 | break; | 464 | break; |
466 | case 't': /* timeout period */ | 465 | case 't': /* timeout period */ |
467 | timeout_interval = atoi (optarg); | 466 | timeout_interval = atoi (optarg); |
@@ -508,13 +507,13 @@ process_arguments (int argc, char **argv) | |||
508 | } | 507 | } |
509 | break; | 508 | break; |
510 | case 'n': /* expect NXDOMAIN */ | 509 | case 'n': /* expect NXDOMAIN */ |
511 | expect_nxdomain = TRUE; | 510 | expect_nxdomain = true; |
512 | break; | 511 | break; |
513 | case 'A': /* expect authority */ | 512 | case 'A': /* expect authority */ |
514 | expect_authority = TRUE; | 513 | expect_authority = true; |
515 | break; | 514 | break; |
516 | case 'L': /* all must match */ | 515 | case 'L': /* all must match */ |
517 | all_match = TRUE; | 516 | all_match = true; |
518 | break; | 517 | break; |
519 | case 'w': | 518 | case 'w': |
520 | warning = optarg; | 519 | warning = optarg; |