summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorRolf Eike Beer <eike@sf-mail.de>2018-07-25 21:14:47 +0200
committerRolf Eike Beer <eike@sf-mail.de>2018-07-25 21:14:47 +0200
commitfd9a7d2e00b2acf66ec9aa48d7f51daa817f3457 (patch)
treeb9ae16700784e587c946f87421e2b86d5c49659b /plugins
parenta03068743f3694cbdbe84bb6e802a41f270cc105 (diff)
downloadmonitoring-plugins-fd9a7d2e00b2acf66ec9aa48d7f51daa817f3457.tar.gz
check_dns: allow forcing complete match of all addresses
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_dns.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 75a9dcaa..25bd31dc 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -56,6 +56,7 @@ char **expected_address = NULL;
56int expected_address_cnt = 0; 56int expected_address_cnt = 0;
57 57
58int expect_authority = FALSE; 58int expect_authority = FALSE;
59int all_match = FALSE;
59thresholds *time_thresholds = NULL; 60thresholds *time_thresholds = NULL;
60 61
61static int 62static int
@@ -228,6 +229,8 @@ main (int argc, char **argv)
228 if (result == STATE_OK && expected_address_cnt > 0) { 229 if (result == STATE_OK && expected_address_cnt > 0) {
229 result = STATE_CRITICAL; 230 result = STATE_CRITICAL;
230 temp_buffer = ""; 231 temp_buffer = "";
232 unsigned long expect_match = (1 << expected_address_cnt) - 1;
233 unsigned long addr_match = (1 << n_addresses) - 1;
231 234
232 for (i=0; i<expected_address_cnt; i++) { 235 for (i=0; i<expected_address_cnt; i++) {
233 int j; 236 int j;
@@ -236,13 +239,17 @@ main (int argc, char **argv)
236 if ( strcmp(addresses[j], expected_address[i]) == 0 239 if ( strcmp(addresses[j], expected_address[i]) == 0
237 || ip_match_cidr(addresses[j], expected_address[i]) ) { 240 || ip_match_cidr(addresses[j], expected_address[i]) ) {
238 result = STATE_OK; 241 result = STATE_OK;
239 break; 242 addr_match &= ~(1 << j);
243 expect_match &= ~(1 << i);
240 } 244 }
241 } 245 }
242 246
243 /* prepare an error string */ 247 /* prepare an error string */
244 xasprintf(&temp_buffer, "%s%s; ", temp_buffer, expected_address[i]); 248 xasprintf(&temp_buffer, "%s%s; ", temp_buffer, expected_address[i]);
245 } 249 }
250 /* check if expected_address must cover all in addresses and none may be missing */
251 if (all_match && (expect_match != 0 || addr_match != 0))
252 result = STATE_CRITICAL;
246 if (result == STATE_CRITICAL) { 253 if (result == STATE_CRITICAL) {
247 /* Strip off last semicolon... */ 254 /* Strip off last semicolon... */
248 temp_buffer[strlen(temp_buffer)-2] = '\0'; 255 temp_buffer[strlen(temp_buffer)-2] = '\0';
@@ -406,6 +413,7 @@ process_arguments (int argc, char **argv)
406 {"reverse-server", required_argument, 0, 'r'}, 413 {"reverse-server", required_argument, 0, 'r'},
407 {"expected-address", required_argument, 0, 'a'}, 414 {"expected-address", required_argument, 0, 'a'},
408 {"expect-authority", no_argument, 0, 'A'}, 415 {"expect-authority", no_argument, 0, 'A'},
416 {"all", no_argument, 0, 'L'},
409 {"warning", required_argument, 0, 'w'}, 417 {"warning", required_argument, 0, 'w'},
410 {"critical", required_argument, 0, 'c'}, 418 {"critical", required_argument, 0, 'c'},
411 {0, 0, 0, 0} 419 {0, 0, 0, 0}
@@ -419,7 +427,7 @@ process_arguments (int argc, char **argv)
419 strcpy (argv[c], "-t"); 427 strcpy (argv[c], "-t");
420 428
421 while (1) { 429 while (1) {
422 c = getopt_long (argc, argv, "hVvAt:H:s:r:a:w:c:", long_opts, &opt_index); 430 c = getopt_long (argc, argv, "hVvALt:H:s:r:a:w:c:", long_opts, &opt_index);
423 431
424 if (c == -1 || c == EOF) 432 if (c == -1 || c == EOF)
425 break; 433 break;
@@ -467,6 +475,9 @@ process_arguments (int argc, char **argv)
467 case 'A': /* expect authority */ 475 case 'A': /* expect authority */
468 expect_authority = TRUE; 476 expect_authority = TRUE;
469 break; 477 break;
478 case 'L': /* all must match */
479 all_match = TRUE;
480 break;
470 case 'w': 481 case 'w':
471 warning = optarg; 482 warning = optarg;
472 break; 483 break;
@@ -542,6 +553,9 @@ print_help (void)
542 printf (" %s\n", _("Return warning if elapsed time exceeds value. Default off")); 553 printf (" %s\n", _("Return warning if elapsed time exceeds value. Default off"));
543 printf (" -c, --critical=seconds\n"); 554 printf (" -c, --critical=seconds\n");
544 printf (" %s\n", _("Return critical if elapsed time exceeds value. Default off")); 555 printf (" %s\n", _("Return critical if elapsed time exceeds value. Default off"));
556 printf (" -L, --all\n");
557 printf (" %s\n", _("Return critical the list of expected addresses does not match all addresses"));
558 printf (" %s\n", _("returned. Default off"));
545 559
546 printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); 560 printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
547 561
@@ -553,5 +567,5 @@ void
553print_usage (void) 567print_usage (void)
554{ 568{
555 printf ("%s\n", _("Usage:")); 569 printf ("%s\n", _("Usage:"));
556 printf ("%s -H host [-s server] [-a expected-address] [-A] [-t timeout] [-w warn] [-c crit]\n", progname); 570 printf ("%s -H host [-s server] [-a expected-address] [-A] [-t timeout] [-w warn] [-c crit] [-L]\n", progname);
557} 571}